﻿//------------------------------------------------------------------------------
// System Name:   Customer Service Platform
// Component:     CIS   DepartmentManagementHelper
// Created By:    Samara Jiang (samaraj@wicresoft.com)
// Created Date:  2011-2-10
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ASBCC.Database.EntityFramework;
using System.Collections;

namespace ASBCC.Business.CIS
{
    /// <summary>
    /// CIS  部门管理模块数据库访问类
    /// </summary>
    public static class DepartmentManagementHelper
    {
        /// <summary>
        /// 将一个DepartmentManagement的激活状态设为未激活
        /// </summary>
        public static bool SetDepartmentDisabled(int departmentID)
        {
            using (var dc = new CCEntities())
            {
                var departmet = dc.CustomerDepartments.FirstOrDefault(p => p.Disabled == false && p.DepartmentID == departmentID);
                if (departmet == null)
                    return false;
                departmet.Customer.Load();
                if (departmet.Customer.Count() > 0)
                    return false;
                else
                {
                    departmet.Disabled = true;
                    dc.SaveChanges();
                    return true;
                }
            }
        }


        /// <summary>
        /// 根据当前ID获取Name
        /// </summary>
        public static IEnumerable getName(int entityID)
        {
            using (var dc = new CCEntities())
            {
                var name = dc.CustomerDepartments.FirstOrDefault(p => p.DepartmentID == entityID).Name;
                return name;
            }
        }

    }
}
